At the next plot we can see the six only municipalities from Spain with more than 500.000 people and their area in km^2.
library(plotly)
## Loading required package: ggplot2
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
cities <- data.frame(name = c("Madrid", "Barcelona", "Valencia", "Sevilla", "Zaragoza", "Málaga"),
pop = c(3334730, 1664182, 800215, 691395, 681877, 578460),
area = c(604.45, 101.35, 134.65, 140.8, 973.78, 398.25),
col = c("> 1 million", "> 1 million", "> 750 thousand", "> 500 thousand", "> 500 thousand", "> 500 thousand"))
plot_ly(cities, x = cities$pop, y = cities$area, mode = "markers", color = as.factor(cities$col))
## No trace type specified:
## Based on info supplied, a 'scatter' trace seems appropriate.
## Read more about this trace type -> https://plotly.com/r/reference/#scatter